<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>weir-权限管理</title>
<meta name="content-type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" href="/sr/style/aurora.ico" type="image/x-icon">
<div th:replace="/pub.html"></div>
<script type="text/javascript">
var west_tree,mainTabs,index_tabsMenu,addTabs,tabsClose;
$(function(){
	west_tree=$('#west_tree').tree({
		lines : true,
		method : 'get',
		url : '/perm/menu/tree/1',
		onLoadSuccess:function(node, data){
			if(data){
				$(data).each(function(index,d){
					if(this.state=='closed'){
						west_tree.tree('expandAll');
					}
				});
			}
		},
		onClick : function(node) {
			if (node.attributes && node.attributes.url) {
				var url = node.attributes.url;
				var tabs = $('#mainTabs');
				var opts = {
					title : node.text,
					closable : true,
					content : '<iframe src="'+url+'" allowTransparency="true" style="border:0;width:100%;height:99%;" frameBorder="0"></iframe>',
					border : false,
					fit : true
				};
				if (tabs.tabs('exists', opts.title)) {
					tabs.tabs('select', opts.title);
				} else {
					tabs.tabs('add', opts);
				}
			}
		},
		onDblClick:function(node){
			if(node.state=='closed'){
				$(this).tree('expand',node.target);
			}else{
				$(this).tree('collapse',node.target);
			}
		}
	});
	
	addTabs = function(url,text,id){
		var tabs = $('#mainTabs');
		var opts = {
			title : text,
			closable : true,
			content : '<iframe id="'+id+'" src="'+url+'" allowTransparency="true" style="border:0;width:100%;height:99%;" frameBorder="0"></iframe>',
			border : false,
			fit : true
		};
		if (tabs.tabs('exists', opts.title)) {
			tabs.tabs('select', opts.title);
		} else {
			tabs.tabs('add', opts);
		}
	}
	
	mainTabs = $('#mainTabs').tabs({
		fit : true,
		border : false,
		onContextMenu : function(e, title) {
			e.preventDefault();
			index_tabsMenu.menu('show', {
				left : e.pageX,
				top : e.pageY
			}).data('tabTitle', title);
		},
		tools : [ {
			text:'全屏',
			iconCls : 'ext-icon-arrow_out',
			handler : function() {
				$("body").layout("full");
			}
		},{
			text:'退出全屏',
			iconCls : 'ext-icon-arrow_in',
			handler : function() {
				$("body").layout("unFull");
			}
		}, {
			text : '刷新',
			iconCls : 'ext-icon-arrow_refresh',
			handler : function() {
				var panel = mainTabs.tabs('getSelected').panel('panel');
				var frame = panel.find('iframe');
				try {
					if (frame.length > 0) {
						for (var i = 0; i < frame.length; i++) {
							frame[i].contentWindow.document.write('');
							frame[i].contentWindow.close();
							frame[i].src = frame[i].src;
						}
						if (navigator.userAgent.indexOf("MSIE") > 0) {// IE特有回收内存方法
							try {
								CollectGarbage();
							} catch (e) {
							}
						}
					}
				} catch (e) {
				}
			}
		}, {
			text : '关闭',
			iconCls : 'ext-icon-cross',
			handler : function() {
				var index = mainTabs.tabs('getTabIndex', mainTabs.tabs('getSelected'));
				var tab = mainTabs.tabs('getTab', index);
				if (tab.panel('options').closable) {
					mainTabs.tabs('close', index);
				} else {
					$.messager.alert('提示', '[' + tab.panel('options').title + ']不可以被关闭！', 'error');
				}
			}
		} ]
	});
	
	index_tabsMenu = $('#index_tabsMenu').menu({
		onClick : function(item) {
			var curTabTitle = $(this).data('tabTitle');
			var type = $(item.target).attr('title');

			if (type === 'refresh') {
				mainTabs.tabs('getTab', curTabTitle).panel('refresh');
				return;
			}

			if (type === 'close') {
				var t = mainTabs.tabs('getTab', curTabTitle);
				if (t.panel('options').closable) {
					mainTabs.tabs('close', curTabTitle);
				}
				return;
			}

			var allTabs = mainTabs.tabs('tabs');
			var closeTabsTitle = [];

			$.each(allTabs, function() {
				var opt = $(this).panel('options');
				if (opt.closable && opt.title != curTabTitle && type === 'closeOther') {
					closeTabsTitle.push(opt.title);
				} else if (opt.closable && type === 'closeAll') {
					closeTabsTitle.push(opt.title);
				}
			});

			for ( var i = 0; i < closeTabsTitle.length; i++) {
				mainTabs.tabs('close', closeTabsTitle[i]);
			}
		}
	});
	tabsClose = function (){
		var index = mainTabs.tabs('getTabIndex', mainTabs.tabs('getSelected'));
		var tab = mainTabs.tabs('getTab', index);
		if (tab.panel('options').closable) {
			mainTabs.tabs('close', index);
		}
	}
});
</script>
</head>

<body class="easyui-layout">
<div data-options="region:'north',href:'north',border:false" style="height: 30px; overflow: hidden;"></div>
	<div data-options="region:'west',href:'',split:true" title="导航" style="width: 200px; padding: 10px;">
		<ul id="west_tree"></ul>
	</div>
	<div data-options="region:'center'" style="overflow: hidden;">
		<div id="mainTabs">
			<div title="权限管理" data-options="iconCls:'logo'">
				<iframe src="welcome" allowTransparency="true" style="border: 0; width: 100%; height: 99%;" frameBorder="0"></iframe>
			</div>
		</div>
	</div>
	<div data-options="region:'south',href:'south',border:false" style="height: 20px; overflow: hidden;"></div>
	
	<div id="index_tabsMenu" style="width: 120px; display: none;">
		<div title="refresh" data-options="iconCls:'transmit'">刷新</div>
		<div class="menu-sep"></div>
		<div title="close" data-options="iconCls:'delete'">关闭</div>
		<div title="closeOther" data-options="iconCls:'delete'">关闭其他</div>
		<div title="closeAll" data-options="iconCls:'delete'">关闭所有</div>
	</div>
</body>
</html>